package ls.vuecp.gui.component;

import java.awt.Color;
import java.awt.Font;
import java.awt.geom.Rectangle2D;

import ls.vuecp.gui.draw.DrawContext;

import tufts.vue.DEBUG;
import tufts.vue.VueConstants;
import tufts.vue.VueResources;
import edu.tufts.vue.preferences.implementations.BooleanPreference;

public abstract class LWIcon extends Rectangle2D.Float
	implements VueConstants
{
	private static final org.apache.log4j.Logger Log = org.apache.log4j.Logger.getLogger(LWIcon.class);
	
	private static final float DefaultScale = 0.045f; // scale to apply to the absolute size of our vector based icons
	private static final Color TextColor = VueResources.getColor("node.icon.color.foreground");
	private static final Color FillColor = VueResources.getColor("node.icon.color.fill");
	public static final Font FONT_ICON = VueResources.getFont("node.icon.font");
	
	private final static BooleanPreference oneClickLaunchResPref = BooleanPreference.create(
			edu.tufts.vue.preferences.PreferenceConstants.INTERACTIONS_CATEGORY,
			"oneClickResLaunch", 
			VueResources.getString("preference.resourcelaunching.title"), 
			VueResources.getString("preference.resourcelaunching.description"),
			Boolean.TRUE,
			true);
	
	protected LWComponent mLWC;
	protected final Color mColor;
	protected float mMinWidth;
	protected float mMinHeight;
	
	/** the cached value of isWanted for isShowing */
	protected boolean isLaidOut;

	private LWIcon(LWComponent lwc, Color c) {
        // default size
        super.width = 22;
        super.height = 12;
        mLWC = lwc;
        mColor = c;
    }
    private LWIcon(LWComponent lwc) {
        this(lwc, TextColor);
    }

//     public static ShowIconsPreference getShowIconPreference()
//     {
//     	return IconPref;
//     }
    public void setLocation(float x, float y)
    {
        super.x = x;
        super.y = y;
    }

    public void setSize(float w, float h)
    {
        super.width = w;
        super.height = h;
    }
    
    /**
     * do we contain coords x,y?
     * Coords may be component local or map local or
     * whataver -- depends on what was handed to us
     * via @see setLocation
     */
    public boolean contains(float x, float y)
    {
        if (isShowing() && super.width > 0 && super.height > 0) {
            return x >= super.x+1
                && y >= super.y+1
                && x <= (super.x + super.width -1)
                && y <= (super.y + super.height -1);
        }
        return false;
    }

    public void setMinimumSize(float w, float h)
    {
        mMinWidth = w;
        mMinHeight = h;
        if (super.width < w)
            super.width = w;
        if (super.height < h)
            super.height = h;
    }

//     public void setColor(Color c) {
//         mColor = c;
//     }
    
    void draw(DrawContext dc)
    {
        if (DEBUG.BOXES) {
            dc.g.setColor(Color.red);
            dc.g.setStroke(STROKE_SIXTEENTH);
            dc.g.draw(this);
        }
    }

    void layout() {} // subclasses can check for changes in here
    
    final boolean isShowing() {
        return isLaidOut;
    }
}
